<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>dom更新时机</h2>
      <p>count: {{ count }}</p>
      <button v-on:click="handleClick">btn</button>
      <ul>
        <li v-for="item in list">{{item}}</li>
      </ul>
      <button v-on:click="fn">btn2</button>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // dom更新不是和数据改变同步进行的
      // 会等待所有的数据都修改结束，再一次性的渲染
      createApp({
        data() {
          return {
            count: 1,
            name: "zhangsan",
            list: [1, 2, 3],
          };
        },
        methods: {
          handleClick() {
            this.count++;
            this.count++;
            this.count++;
            this.name = "lisi";

            // this.count++;
            // setTimeout(() => {
            //   this.count++;
            // }, 0);

            // this.$nextTick表示等待页面渲染结束后再执行
            // 下一次事件循环再执行
            // this.count++;
            // this.$nextTick(() => {
            //   this.count++;
            // });
          },
          fn() {
            this.list.push(4);
            this.$nextTick(() => {
              console.log(document.querySelector("ul").offsetHeight);
            });
          },
        },
        // mounted() {
        //   // 获取ul元素的高度
        //   console.log(document.querySelector("ul").offsetHeight);
        // },
      }).mount("#app");
    </script>
  </body>
</html>
